import Router from 'koa-router';
import { 
  getCategories, 
  getCategoryById, 
  createCategory, 
  updateCategory, 
  deleteCategory,
  updateCategoriesOrder
} from '../controllers/category.controller';
import { authMiddleware } from '../middlewares/auth.middleware';
import { roleMiddleware } from '../middlewares/role.middleware';

const router = new Router();

/**
 * @route GET /api/categories
 * @desc 获取分类列表
 * @access Public
 */
router.get('/', getCategories);

/**
 * @route GET /api/categories/:id
 * @desc 获取分类详情
 * @access Public
 */
router.get('/:id', getCategoryById);

/**
 * @route POST /api/categories
 * @desc 创建分类
 * @access Private (需要管理员或编辑角色)
 */
router.post('/', authMiddleware, roleMiddleware(['admin', 'editor']), createCategory);

/**
 * @route PUT /api/categories/:id
 * @desc 更新分类
 * @access Private (需要管理员或编辑角色)
 */
router.put('/:id', authMiddleware, roleMiddleware(['admin', 'editor']), updateCategory);

/**
 * @route DELETE /api/categories/:id
 * @desc 删除分类
 * @access Private (需要管理员或编辑角色)
 */
router.delete('/:id', authMiddleware, roleMiddleware(['admin', 'editor']), deleteCategory);

/**
 * @route PATCH /api/categories/order
 * @desc 更新分类排序
 * @access Private (需要管理员或编辑角色)
 */
router.patch('/order', authMiddleware, roleMiddleware(['admin', 'editor']), updateCategoriesOrder);

export default router; 